﻿using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;

namespace Miao.Stand
{

    public static class StandVerbAbilityPathches
    {
        public static bool get_DirectOwner_Prefix(Verb __instance, ref IVerbOwner __result)
        {
            if (__instance is Verb_StandUseAbility)
            {
                __result = __instance.CasterPawn;
                return false;
            }
            return true;
        }
        public static bool ConfirmStillValid(Targeter __instance, Pawn ___caster)
        {
            if (__instance.targetingSource is Verb_StandUseAbility v)//这里只结算第一方
            {
                if (v != null)
                {
                    var selector = Find.Selector;
                    if (v.Caster.Map != Find.CurrentMap ||
                        v.Caster.Destroyed ||
                        (!v.GetVerb?.Available() ?? false))
                    {
                        __instance.StopTargeting();
                    }
                    else
                    {
                        if (__instance.targetingSourceAdditionalPawns != null)//这里好像搜索多选设定
                            foreach (var additionalPawn in __instance.targetingSourceAdditionalPawns)
                                if (additionalPawn.Destroyed)
                                {
                                    __instance.StopTargeting();
                                    break;
                                }
                    }
                }
                return false;
            }
            return true;
        }

    }

}
